﻿using System;
using System.Windows.Media;
using System.Windows.Data;

namespace ReflectionStudio.Controls
{
	/// <summary>
	/// Converter : Enum to string and revert
	/// </summary>
    [ValueConversion(typeof(object), typeof(object))]
    public class QtyColorConverter : IValueConverter
	{
		/// <summary>
		/// IValueConverter.Convert
		/// </summary>
		/// <param name="value"></param>
		/// <param name="targetType"></param>
		/// <param name="parameter"></param>
		/// <param name="culture"></param>
		/// <returns></returns>
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{

            if (value == null)
            {
                value = "0";
            }
            if (value.ToString().Trim() == "")
                value = "0";
            double v =System.Math.Abs( System.Convert.ToDouble(value.ToString().Trim()));
            object vR = new SolidColorBrush(Colors.Black);
            if (v >5 && v <= 15)
            {
                vR = new SolidColorBrush(Colors.Purple);                 
            }
            if (v > 15)
            {
                vR = new SolidColorBrush(Colors.Red); 
            }           
             return vR;
		}

		/// <summary>
		/// IValueConverter.ConvertBack
		/// </summary>
		/// <param name="value"></param>
		/// <param name="targetType"></param>
		/// <param name="parameter"></param>
		/// <param name="culture"></param>
		/// <returns></returns>
		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
            return 0;
            if (value == null)
                return 0;
            if (value.GetType().ToString() != "SolidColorBrush")
                return 0;
            if (((SolidColorBrush)value).Color == Colors.YellowGreen)
                return 15;
            if (((SolidColorBrush)value).Color == Colors.DarkRed)
                return 7;
            else
                return 0; 
		}
	}
}
